package com.yx.filesystem.client;

import java.io.File;
import java.io.FileInputStream;

public class TestClient {

	public TestClient() {
		String[] server = { "192.168.0.102:9997", "192.168.0.102:9992" };
		try {
			StorageClientManager.init(server,512,512);
			System.out.println("OK!"+ StorageClientManager.getAliveServerCount(true));
			while (StorageClientManager.getAliveServerCount(true) <1) {				
				synchronized (this) {
					try {
						wait(1000);
					} catch (Exception e) {
					}
				}
			}
			System.out.println("ttt!"+ StorageClientManager.getAliveServerCount(true));

			for (int i = 1; i < 2; i++) {
				(new RunThread(i)).start();
			}

			 //String name ="000010000220151023111324000000000016";
			 //for (int i = 1; i < 10; i++) {
			//	 long t = System.currentTimeMillis();
			//	 Client client = StorageClientManager.get(name);
			//	 client.getFile(new FileOutputStream(new File("e:/eee.jpg"),false));
			//	 System.out.println("download:"+(System.currentTimeMillis() - t));
			// }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new TestClient();

	}

	public class RunThread extends Thread {
		int ii = 0;

		public RunThread(int i) {
			this.ii = i;
		}

		public void run() {
			try {
				for (int i = 0; i < 30; i++) {
					long t = System.currentTimeMillis();
					File file = new File("E:/IMG_" + ii + ".JPG");
					FileInputStream in = new FileInputStream(file);
					FileController client = StorageClientManager.get();
					String name = client.write("E:/IMG_" + ii + ".JPG",in, file.length());
					System.out.println(name);
					System.out.println(System.currentTimeMillis() - t);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}
